package com.yl.chainStore.services.impl.sick

import com.baomidou.mybatisplus.core.toolkit.Wrappers
import com.yl.chainStore.entity.user.CompanyUserMedicalHistoryModel
import com.yl.chainStore.entity.user.CompanyUserMedicalHistoryModelType
import com.yl.chainStore.mapper.user.CompanyUserMedicalHistoryModelMapper
import com.yl.chainStore.mapper.user.CompanyUserMedicalHistoryModelTypeMapper
import com.yl.chainStore.services.sick.ICompanyUserMedicalHistoryModelTypeService
import com.yl.chainStore.services.warehouse.IWarehouseCheckOrderService
import com.yl.common.ErrorCode
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnError
import com.yl.common.control.returnSuccess
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

@Service
class CompanyUserMedicalHistoryModelTypeServiceImpl(
	private val companyUserMedicalHistoryModelMapper: CompanyUserMedicalHistoryModelMapper,
	private val companyUserMedicalHistoryModelTypeMapper: CompanyUserMedicalHistoryModelTypeMapper,
) : ICompanyUserMedicalHistoryModelTypeService {

	companion object {
		private val log = LoggerFactory.getLogger(ICompanyUserMedicalHistoryModelTypeService::class.java)
	}

	override fun addModel(model: CompanyUserMedicalHistoryModel): ResponseBody {
		log.info("用户病历模板类型 ==> 添加模板 model:{},", model)
		companyUserMedicalHistoryModelMapper.insert(model)
		return returnSuccess()
	}

	override fun updateModelType(modelType: CompanyUserMedicalHistoryModelType): ResponseBody {
		log.info("用户病历模板类型 ==> 修改类型 modelType:{},", modelType)

		val type = companyUserMedicalHistoryModelTypeMapper.selectById(modelType.id)
			?: return returnError(ErrorCode.DATA_IS_NOT_FIND, "未找到修改对象，请刷新后重试")
		type.name = modelType.name
		type.orderNum = modelType.orderNum
		companyUserMedicalHistoryModelTypeMapper.updateById(type)
		return returnSuccess()
	}

	override fun delType(typeId: Long): ResponseBody {
		log.info("用户病历模板类型 ==> 删除类型 typeId:{},", typeId)
		companyUserMedicalHistoryModelMapper.delete(
			Wrappers.query<CompanyUserMedicalHistoryModel?>().eq("type_id", typeId)
		)
		companyUserMedicalHistoryModelTypeMapper.deleteById(typeId)
		return returnSuccess()
	}

	override fun delModel(modelId: Long): ResponseBody {
		log.info("用户病历模板类型 ==> 删除模板 modelId:{},", modelId)
		companyUserMedicalHistoryModelMapper.deleteById(modelId)
		return returnSuccess()
	}

	override fun updateModel(model: CompanyUserMedicalHistoryModel): ResponseBody {
		log.info("用户病历模板类型 ==> 修改模板 model:{},", model)
		companyUserMedicalHistoryModelMapper.updateById(model)
		return returnSuccess()
	}

}
